function clear() {
        $('.result-project-name').val(''),
        $('.time input').val(''),
        $('.result-remark').val('');
        $('#confEname_edit').val('');
        $('#allI').val('');

}

$(document).ready(function () {
    query();
});

function query() {

    var queryjson;

    queryjson = {}
    //发送ajax;
    $.ajax(
        {
            type: "post",
            url: "/market/list",
            data: queryjson,
            dataType: "json",
            success: function (data) {
                var data = data.data;
                var tmpl = bt('listtmp', data);
                // $('ruleslist').html(tmpl);
                document.getElementById('list').innerHTML = tmpl;
                return tmpl;
            }, error: function () {
            alert("报错了");
        }
        }
    );
}


function show_market_add(){
    $('#result-pop').show();
    $('#confName_edit').removeAttr("readonly");
    $('#confEname_edit').removeAttr("readonly");
    clear();
}


//编辑
function show_market_update(obj) {

    var that = this;
    //弹出第一次的提示框
    $('#operate-before-pop').show();
    //点击确定 弹出编辑框
    $('.operate-before-confirm').off('click').on('click', function () {
        $('#operate-before-pop').hide();
        //需要回填数据
        $('#result-pop .cms-modal-title').html('修改通话效果参数');
        var tr = $(obj).parents("tr");
        $('#confName_edit').val(tr.find('.confName').text());
        $('#confEname_edit').val(tr.find('.confEname').text());
        $('#confValue_edit').val(tr.find('.confValue').text());
        $('#remark_edit').val(tr.find('.remark').text());
        $('#allId').val($(obj).attr('id-value'));
        $('#result-pop').show();
        $('#confName_edit').attr('readonly', 'readonly')
        $('#confEname_edit').attr('readonly', 'readonly')
    })
}
function activeRule(obj) {
    var s = $(obj).attr('data-value')
    var allId = $(obj).attr('id-value')
    var allConfig = {allId: allId};
    var url = "/operate/tostopConfig";
    if (s == "1") {
        url = "/operate/stop";
    } else {
        url = "/operate/active";
    }
    $.ajax({
        type: "post",
        url: url,
        async: false,
        data: allConfig,
        success: function () {
            alert("保存成功");
            query();
        }
    });
}
$('.cms-cancel').on("click",function(){
    cancelbtn();
});

function cancelbtn(){
    clear();
    $('#result-pop').hide();
    $('#operate-before-pop').hide();
    $('#operate-after-pop').hide();
}

//启用停用
function changeStatus(obj) {
    var that = this;
    //当前状态为启用
    //弹出第一次的提示框
    $('#operate-before-pop').show();
    //点击确定 弹出编辑框
    $('.operate-before-confirm').off('click').on('click', function () {
        $('#operate-before-pop').hide();
        //第二次提示弹出
        $('#operate-after-pop').show();
        $('.operate-after-confirm').off('click').on('click', function () {
            activeRule(obj);
            if ($(that).hasClass('result-status-active')) {
                $(that).removeClass('result-status-active').html('停用');
            } else {
                $(that).addClass('result-status-active').html('启用');
            }
            $('#operate-after-pop').hide();
        })

    })
}

function market_update_save(){
    $('#result-pop').validate();
    //先隐藏编辑框
    $('#rate-pop').hide();
    //弹出第二次提示框
    $('#operate-after-pop').show();
    //第二次点击确定发送请求
    $('.operate-after-confirm').off('click').on('click', function () {
        var confName_edit = $('#confName_edit').val();
        var confEname_edit = $('#confEname_edit').val();
        var confValue_edit = $('#confValue_edit').val();
        var remark_edit = $('#remark_edit').val();
        var allId= $("#allId").val();
        var url;
        if(allId){
            url="/operate/update";
        }else{
            url="/operate/add"
        }
        var allConfig = {allId: allId, confValue: confValue_edit, remark: remark_edit, confName: confName_edit ,confEname:confEname_edit,confType:30};
        $.ajax({
            type: "post",
            url: url,
            data: allConfig,
            dataType: "json",
            success: function (data) {
                if(data.code==0){
                    alert(data.msg);
                }
                query();
            }
        });
        clear();
        $('#operate-after-pop').hide();
    })
    $('#result-pop').hide();
}

